<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/14 0014
 * Time: 19:02
 */

namespace App\Repositories\Admin;


use App\Models\Admin\Category;

class CategoryRepository
{
    /*
           * @ 通过分组id查询分组信息
           * @ 返回分组相关的完整信息
           */
    public function getById($id){
        return Category::where('category_id',$id)->with(['categorysType'])->first();
    }
    /*
     * @ 查询所有分组信息
     * @ 返回分组相关的完整信息
     */
    public function getAll(){
        return Category::with(['categorysType'])->get();
    }
    /*
     * @ 通过多条件查询分组
     */
    public function getByMore($where){
        return Category::where($where)->with('categorysType')->get();
    }

    /**
     * 分组查询 且状态为1 正常
     */
    public function getOrderByTypeAndStatus(){
        return Category::where('category_status',1)->orderBy('category_id', 'asc')->with('categorysType')->get();
    }
    /**
     * @ 添加分组的信息
     * @ 返回的是 Category模型对象
     */
    public function createCategory($category){
        return Category::create($category);
    }
    /**
     * 修改category_check字段的值
     */
    public function updateStatus($id,$value){
        $category = Category::find($id);
        $category->category_status = $value;
        return $category->save();
    }

    /**
     * 删除分组
     */
    public function delect($id){
        return Category::where('category_id','=',$id)
            ->delete();
    }
}